package com.lbj.yuanxi.tool

import android.content.res.Resources

// DP 转换为 PX  +0.5f 四舍五入
fun Int.dp2px(): Int = (0.5f + this * Resources.getSystem().displayMetrics.density).toInt()
fun Int.dp2pxF(): Float = 0.5f + this * Resources.getSystem().displayMetrics.density
fun Float.dp2px(): Int = (0.5f + this * Resources.getSystem().displayMetrics.density).toInt()
fun Float.dp2pxF(): Float = 0.5f + this * Resources.getSystem().displayMetrics.density

// SP 转换为 PX +0.5f 四舍五入
fun Int.sp2px(): Int = (0.5f + this * Resources.getSystem().displayMetrics.scaledDensity).toInt()
fun Int.sp2pxF(): Float = 0.5f + this * Resources.getSystem().displayMetrics.scaledDensity

// PX 转换为 DP
fun Int.px2dp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()
